﻿using System;
using System.Collections.Generic;

namespace InternetSpiderLib.Scenes.Filters
{
    /// <summary>
    /// 内容包含过滤器
    /// （传递过来的数据中包含此数据则认为正常）
    /// </summary>
    public class ContainsSceneFilter : ISceneFilter
    {
        public string Key { get; set; }

        public string TypeName { get; set; }

        public bool Filter(DataBox data)
        {
            if (string.IsNullOrEmpty(TypeName))
                return false;

            var type = Type.GetType(TypeName);
            if (type == null)
                return false;

            if (string.IsNullOrEmpty(Key) || type == null)
                return false;

            return data.Get(Key, type) != null;
        }
    }
}
